package com.tiem_files.dao;

import com.tiem_files.dao.base.BaseDao;
import com.tiem_files.model.Dept;
import com.tiem_files.utils.JDBCUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.MapHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DeptDao extends BaseDao<Dept> {

    public DeptDao() {
        super(Dept.class);
    }

    public  List<Dept> findAll(){
        String sql = "select * from dept";
        QueryRunner qr = new QueryRunner(JDBCUtil.getDataSource());
       List<Dept> deptList=new ArrayList<>();
        try {
            deptList= qr.query(sql, new BeanListHandler<>(Dept.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return deptList;
    }
}
